#!/bin/bash

NAME=mysql-master
PORT=3306
PASSWORD=111111
TAG=5.7.39

while getopts "n:p:a:t:" opt; do
  case $opt in
    n)
        NAME=$OPTARG
        ;;
    p)
        PORT=$OPTARG
        ;;
    a)
        PASSWORD=$OPTARG
        ;;
    t)
        TAG=$OPTARG
        ;;
    \?)
        echo "invalid arg"
        exit 1
        ;;
  esac
done

docker run \
--restart always \
--name ${NAME} \
-p ${PORT}:3306 \
-v ${PWD}/conf/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \
-v ${PWD}/data:/var/lib/mysql \
-v ${PWD}/logs:/var/log/mysql \
-e MYSQL_ROOT_PASSWORD=${PASSWORD} \
-d mysql:${TAG}